﻿using System;
using System.Net;

namespace FBGraph
{
    /// <summary>Miscellaneous static methods that provide various lower-level assistance for handling responses from the Graph API.</summary>
    public static class FBGraphApiHelper
    {
        /// <summary>Attempts to handle a <see cref="WebException" /> thrown by a request to the Graph API.</summary>
        /// <param name="ex">The <see cref="WebException" /> that was thrown.</param>
        /// <param name="fgex">An instance of <see cref="FBGraphApiException" /> containing detailed information about the Graph API error.</param>
        /// <returns><c>true</c> if <paramref name="ex" /> was able to be processed as a <see cref="FBGraphApiException" />; otherwise, <c>false</c>.</returns>
        public static Boolean HandleApiError(WebException ex, out FBGraphApiException fgex)
        {
            if (ex.Response == null)
            {
                fgex = null;
                return false;
            }
            else
            {
                fgex = new FBGraphApiException(ex);
                return true;
            }
        }
    }
}